package com.example.zuoye.service.impl;

import com.example.zuoye.dao.CommentsDAO;
import com.example.zuoye.entity.CommentsReply;
import com.example.zuoye.entity.CommentsRoot;
import com.example.zuoye.entity.Liked;
import com.example.zuoye.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentServiceImpl implements CommentService {

    @Autowired
    CommentsDAO commentsDAO;

    @Override
    public List<CommentsRoot> findByOwnerIdService(String ownerId) {
        if (ownerId == null || ownerId.equals("")){
            return null;
        }
        return commentsDAO.findByOwnerId(ownerId);
    }

    @Override
    public boolean addRootCommentsService(CommentsRoot commentsRoot) {
        if (commentsRoot == null){
            return false;
        }
        return commentsDAO.addRootComments(commentsRoot);
    }

    @Override
    public boolean addSonCommentsService(CommentsReply commentsReply) {
        if (commentsReply == null){
            return false;
        }
        return commentsDAO.addSonComments(commentsReply);
    }

    @Override
    public boolean addLikedService(Liked liked) {
        if (liked == null){
            return false;
        }
        return commentsDAO.addLiked(liked);
    }

    @Override
    public List<Liked> getListLikedService(String userId) {
        return commentsDAO.getListLiked(userId);
    }

    @Override
    public boolean updateLikedService(Liked liked) {
        return commentsDAO.upadateLiked(liked);
    }

    @Override
    public Liked checkedLikeService(Liked liked) {
        return commentsDAO.checkedLike(liked);
    }

    @Override
    public boolean updateRootLikeNumService(Liked liked) {
        return commentsDAO.updateRootLikeNum(liked);
    }

    @Override
    public boolean updateReplyLikeNumService(Liked liked) {
        return commentsDAO.updateRootLikeNum(liked);
    }
}
